fix(replication): propagate per-event expiresAt to record writes - #639
Merged
Conversation
Two issues prevented replicated records from being evicted: 1. The `options` object passed to `_writeUpdate` for each replicated event did not include `expiresAt`. In a multi-record transaction batch every event after the first uses the first event as `context`, so `context.expiresAt` would silently apply the wrong expiration (or none) to subsequent records. 2. `_writeUpdate` read `expiresAt` only from `context`, so per-event options were ignored. Now: `options?.expiresAt ?? context?.expiresAt ?? fallback`. 3. `scheduleCleanup()` was only armed when `context.expiresAt` was truthy, missing replicated writes that carry expiration via options. Changed to `if (expiresAt >= 0)` to cover both paths. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced May 20, 2026
Devin-Holland
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Records received via replication were not being evicted by the cleanup scanner even when they carried an
expiresAtvalue. Three issues:1.
expiresAtmissing from options passed to_writeUpdateIn a multi-record transaction batch, every event after the first is processed with
txnInProgress(the first event) ascontext. Subsequent events had noexpiresAtin theiroptions, so_writeUpdatesawcontext.expiresAtfrom the first record applied to all records — or saw nothing if the first record had no expiration.2.
_writeUpdatedidn't readexpiresAtfrom options3.
scheduleCleanup()not armed for replicated writesRelationship to v4 cross-version replication
When receiving a table copy from a v4 peer,
auditRecord.expiresAtmay beundefineddue to a separate encoding bug in v4's table copy path (see harperdb/harperdb#3120). The fallbackexpirationMs + Date.now()in point 2 above handles this case: if the v5 table is pre-configured with anexpirationvalue before connecting to the v4 cluster, the receiver computes a freshexpiresAtat receipt time.Test plan
Integration test
replicationTopology.test.mjscovers both cases:Signed-off by Claude